package cn.java.exercises;

public class JPen
{
    protected String model;
    protected String nib;
    protected double weight;

    public JPen(String model, String nib, double weight)
    {
        this.model = model;
        this.nib = nib;
        this.weight = weight;
    }

    protected String printPenInfo()
    {
        return "";
    }
}


class JHeroPen extends JPen
{
    public static String brand="英雄";
    private String color;

    public JHeroPen(String model, String nib, double weight, String color)
    {
        super(model, nib, weight);
        this.color = color;
    }

    @Override
    protected String printPenInfo()
    {
        String info=String.format("品牌:%s，型号:%s,笔尖:%s,重量:%2.0f克，颜色:%s",
                                  brand,this.model,this.nib,this.weight,this.color);
        System.out.println(info);
        return info;
    }
}

class JSailorPen extends JPen
{
    public static String brand="写乐";
    private int length;

    public JSailorPen(String model, String nib, double weight, int  length)
    {
        super(model, nib, weight);
        this.length = length;
    }

    @Override
    protected String printPenInfo()
    {
        String info=String.format("品牌:%s，型号:%s,笔尖:%s,重量:%2.0f克，长度:%d毫米",
                brand,this.model,this.nib,this.weight,this.length);
        System.out.println(info);
        return info;
    }
}

class PenDemo
{
    public static void main(String[] args)
    {
        JPen pen=new JHeroPen("100","14K",21,"黑色");
        pen.printPenInfo();
        pen=new JSailorPen("写乐","21K",17,135);
        pen.printPenInfo();
    }
}
